home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / DOS / exall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-17  |  2.1 KB  |  104 lines

  1. /* an example of how to use ExAll */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/ports.h>
  5. #include <exec/memory.h>
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8. #include <dos/exall.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/dos_protos.h>
  11.  
  12. #include <stdio.h>
  13.  
  14. /* normally you'ld include pragmas here */
  15.  
  16. #define BUFFSIZE 300
  17.  
  18. int
  19. main(argc,argv)
  20.     int argc;
  21.     char *argv[];
  22. {
  23.     BPTR obj_lock;
  24.     LONG res2,more;
  25.     struct ExAllData *Buffer,*ead;
  26.     struct ExAllControl *control;
  27.     LONG rc = RETURN_ERROR;
  28.     char pattern[256];
  29.  
  30.   /* ugly argument parsing */
  31.   if( argc >= 2 && argc <= 3) {
  32.  
  33.     /* control MUST be allocated by AllocDosObject! */
  34.     control=(struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL,NULL);
  35.     Buffer=(struct ExAllData *) AllocMem(BUFFSIZE,MEMF_PUBLIC|MEMF_CLEAR);
  36.  
  37.     /* always check allocations! */
  38.     if (!control || !Buffer)
  39.         goto cleanup;
  40.  
  41.     if (argc == 3)
  42.     {
  43.         /* parse the pattern for eac_MatchString */
  44.         if (ParsePatternNoCase(argv[2],pattern,sizeof(pattern)) == -1)
  45.         {
  46.             printf("ParsePatternNoCase buffer overflow!\n");
  47.             goto cleanup;
  48.         }
  49.         control->eac_MatchString = pattern;
  50.     }
  51.  
  52.     /* lock the directory */
  53.     if (obj_lock = Lock(argv[1],SHARED_LOCK)) {
  54.  
  55.       control->eac_LastKey = 0;    /* paranoia */
  56.  
  57.       do { /* while more */
  58.  
  59.         more = ExAll(obj_lock,Buffer,BUFFSIZE,ED_TYPE,control);
  60.         res2 = IoErr();
  61.         if (!more && res2 != ERROR_NO_MORE_ENTRIES)
  62.         {
  63.         VPrintf("Abnormal exit, error = %ld\n",&res2);
  64.         break;
  65.         }
  66.  
  67.         /* remember, VPrintf wants a pointer to arguments! */
  68.         VPrintf("Returned %ld entries:\n\n",&(control->eac_Entries));
  69.  
  70.         if (control->eac_Entries)
  71.         {
  72.         ead = Buffer;
  73.         do {
  74.             VPrintf("%s",(LONG *) &(ead->ed_Name));
  75.             if (ead->ed_Type > 0)
  76.                 PutStr(" (dir)\n");
  77.             else
  78.                 PutStr(" (file)\n");
  79.  
  80.             ead = ead->ed_Next;
  81.         } while (ead);
  82.         }
  83.  
  84.         rc = RETURN_OK;    /* success */
  85.  
  86.       } while (more);
  87.  
  88.       UnLock(obj_lock);
  89.  
  90.     } else VPrintf("Couldn't find %s\n",(LONG *) &(argv[1]));
  91.  
  92. cleanup:
  93.     if (Buffer)  FreeMem(Buffer,BUFFSIZE);
  94.     if (control) FreeDosObject(DOS_EXALLCONTROL,control);
  95.  
  96.     return(rc);
  97.  
  98.     } else {
  99.       VPrintf("Usage: %s dirname [pattern]\n",(LONG *) &(argv[0]));
  100.       return(rc);
  101.     }
  102. }
  103.  
  104.